<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itcast" uri="http://itcast.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新闻管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Modern Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
 <!-- Bootstrap Core CSS -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.css">
<!-- Custom CSS -->
<link href="${pageContext.request.contextPath }/css/style1.css" rel='stylesheet' type='text/css' />
<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css"> 
<!-- jQuery -->
<script src="${pageContext.request.contextPath }/js/jquery-1.11.0.js"></script>
<!--kindeditor的js  -->
<script charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor/kindeditor-all-min.js" type="text/javascript"></script>
<script charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor/lang/zh-CN.js" type="text/javascript"></script>
<!-- ajax图片上传的js -->
<script src="${pageContext.request.contextPath }/js/jquery-form.js"></script>
<!---//webfonts--->  
<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath }/js/bootstrap.js"></script>

<script type="text/javascript">  
			var editor;
			KindEditor.ready(function(K) {
			  editor = K.create('textarea[name="contenttt"]', {
				  items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
		                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
		                'insertunorderedlist', '|', 'emoticons', 'image', 'link','|','code','|','preview'],
				  	afterBlur:function(){this.sync();},
			        resizeType: 1,
			        <%-- uploadJson : '+<%=basePath%>+'AdminNews/uploadvvv',// 上传图片接口  项目名（此处项目名是wenjiqiwu）+上传图片的路径
	                filePostName: 'imgFile',// name属性默认值  --%>
			        allowPreviewEmoticons: false
			    });
			    
			});
</script>

<script type="text/javascript">  
			var editorr;
			KindEditor.ready(function(K) {
			  editorr = K.create('textarea[name="newscontent"]', {
				  items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
		                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
		                'insertunorderedlist', '|', 'emoticons', 'image', 'link','|','code','|','preview'],
				  	afterBlur:function(){this.sync();},
			        resizeType: 1,
			        <%-- uploadJson : '+<%=basePath%>+'AdminNews/uploadvvv',// 上传图片接口  项目名（此处项目名是wenjiqiwu）+上传图片的路径
	                filePostName: 'imgFile',// name属性默认值  --%>
			        allowPreviewEmoticons: false
			    });
			    
			});
</script>

    <script>
    	 /*全选或全不选*/
			//1.页面加载
			$(function(){
				//2.获取下面的复选框并将其选中状态设置跟编码的前端复选框保持一致
				$("#select").click(function(){
					 //atrr方法与JQ的版本有关，在1.8.3以下有关
					//$("tbody input[class='selectOne']").attr("checked",this.checked);
					$("tbody input[class='selectOne']").prop("checked",this.checked);
					
				});
			});
			/*全选删除*/
			function jjj(){
				var pList = "";
	            $("[name='all']").each(function () {
	                if ($(this).is(':checked')) {
	                    pList += $(this).val() + ",";
	                }
	            });
	            //去除最后的，
	           pList=pList.substr(0,pList.length-1);
	           var ids = pList;
	           if(pList==""){
	           	alert("请选择");
	           }else{
	           	var yes = confirm("您确定要删除所选项?");
	           	if(yes){
	           		$.post(
	           			"<%=basePath%>adminNews/deleteNewss.html",
	           			{"ids":ids},
	           			function (data) {
							alert("删除成功!");
							location.href="<%=basePath%>adminNews/Newslist.html";
						}
	           		);
	           	}
	           }

			}
	
		</script>

</head>
<body>
<div id="wrapper">
     <!-- Navigation -->
         <jsp:include page="/WEB-INF/jsp/admin/common.jsp"></jsp:include>
        
        
        <div id="page-wrapper">
           <div class="row" style="background-color: wheat;">
           <div class=""></div>
              <div class="col-lg-8 navbar-left" style="padding-top: 15px;margin-left:10px;">
               <form class="form-inline" id="" action="${pageContext.request.contextPath }/adminNews/Newslist.html" method="post">
               	      <div class="form-group">
					    <label for="ntitle">标题:</label>
					    <input type="text" class="form-control" id="ntitle" name="ntitle" value="${ntitle }" placeholder="标题...">
					  </div>
					 
					  <div class="form-group">
					    <label for="nwriter">作者：</label>
					    <input type="text" class="form-control" id="nwriter" name="nwriter" value="${nwriter }" placeholder="作者...">
					  </div>
					  
					   <div class="form-group">
					    <label for="nishot">热门:</label>
					    <select id="nishot" name="nishot">
									<option value="">--请选择--</option>
									<option value="1" <c:if test="${nishot==1 }">selected</c:if>>是</option>
									<option value="2" <c:if test="${nishot==2 }">selected</c:if>>否</option>
								</select>
					  </div>
					  
					  <div class="form-group">
					    <label for="nisshow">发布:</label>
					    <select id="nisshow" name="nisshow">
									<option value="">--请选择--</option>
									<option value="1" <c:if test="${nisshow==1 }">selected</c:if>>是</option>
									<option value="2" <c:if test="${nisshow==2 }">selected</c:if>>否</option>
								</select>
					  </div>
						  
					  <button type="submit" class="btn btn-default">搜索</button>
					</form>
              </div>
              
           
              <div class="col-md-2 navbar-right" style="padding-top: 15px;">
						
									<!--<span class="glyphicon glyphicon-edit"></span>-->
									<button class="btn btn-info btn-sm glyphicon glyphicon-plus" data-toggle="modal" data-target="#myModal2">
											添加
											</button>
								
					</div>
           </div>
           
        <div class="row">
        <div class="col-md-12">  
  	       <h3>新闻管理</h3>
  	        <div class="bs-example4" data-example-id="contextual-table">
              <table class="table table-hover">
	             <caption><input type="checkbox" id="select">
	             	<a href="#" class="btn btn-danger btn-sm" onclick="jjj()">
									<span class="glyphicon glyphicon-trash"></span> 批量删除
								</a>
	             </input>
	             </caption>
					<thead>
						<tr>
							<th>序号</th>
							<th>标题</th>
							<th>作者</th>
							<th>时间</th>
							<th>图片</th>
							<th>是否热门</th>
							<th>是否发布</th>
							<th>操作</th>
							
						</tr>
					</thead>
						<tbody>
						<c:forEach var="row" items="${page.rows }" varStatus="vs">
							<tr>
								<td><input type="checkbox" class="selectOne" value="${row.id }" name="all"/><span id="" style="padding-left: 5px;">${vs.count }</span></td>
								<td>${row.title }</td>
								<td>${row.writer }</td>
								<td>${row.created }</td>
								<td>
									 <img src="${row.image }" class="img-thumbnail" alt="Cinque Terre" width="30px" height="30px">
								</td>
								<td>${row.ishot ==1?"是":"否" }</td>
								<td>${row.isshow ==1?"是":"否" }</td>
								<td>
								<!--编辑-->
								<a href="#" onclick="editNews(${row.id})">
									<!--<span class="glyphicon glyphicon-edit"></span>-->
									<button class="btn btn-info btn-sm glyphicon glyphicon-edit" data-toggle="modal" data-target="#myModal">
											编辑
											</button>			
								</a>
								&nbsp;&nbsp;
								<!--删除-->							
								<a href="#" class="btn btn-danger btn-sm" onclick="deleteNews(${row.id })">
									<span class="glyphicon glyphicon-trash"></span> 删除
								</a>
							</td>	
							</tr>
							</c:forEach>
					</tbody>
				</table>
				<div class="col-md-12 text-right">
							<span>共<font style="color: red;">${total}</font>条数据</span><itcast:page url="${pageContext.request.contextPath }/adminNews/Newslist.html" />
						</div>
             </div>
            </div>
            </div>
            
            
      </div>
      <!-- /#page-wrapper -->
   </div>
   
   <!--添加弹出层-->
   <div class="update_modal">
		
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModal2Label" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" style="background-color:#A6A6A6;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
						<h4 class="modal-title" id="myModal2Label">
					添加新闻
				</h4>
					
					<form class="form-horizontal" role="form" action="" id="newsaveform" method="post" enctype="multipart/form-data">
						
	                    
						<div class="form-group">
							<label for="title1" class="col-sm-2 control-label">标题</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="title1" name="title">
							</div>
						</div>
						
						<div class="form-group">
							<label for="writer1" class="col-sm-2 control-label">作者</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="writer1" name="writer">
							</div>
						</div>
						
						<div class="form-group">
							<label for="image1" class="col-sm-2 control-label">图片</label>
							<div class="col-sm-4">
								<img id="image1" name="image1" src="../img/1.jpg" width="50px" height="50px" class="hidden"/>
    							<input type="hidden" name="image" id="picc" value="">
								<input type="file" name="imgss1" id="imgss1" onchange="imgfun12()">
							</div>
						</div>
						
						<div class="form-group">
							<label for="desc1" class="col-sm-2 control-label">描述</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="desc1" name="desc">
							</div>
						</div>
						
						<div class="form-group">
							<label for="ishot1" class="col-sm-2 control-label">是否热门</label>
							<div class="col-sm-4">
								<select id="ishot1" name="ishot">
								<option value="">请选择</option>
								<option value="1">是</option>
								<option value="2">否</option>
								</select>
							</div>
						</div>
						
						<div class="form-group">
							<label for="isshow1" class="col-sm-2 control-label">是否发布</label>
							<div class="col-sm-4">
								<select id="isshow1" name="isshow">
								<option value="">请选择</option>
								<option value="1">是</option>
								<option value="2">否</option>
								</select>
							</div>
						</div>
						
						
						
						<div class="form-group">
							<label for="content1" class="col-sm-2 control-label">内容</label>
							<div class="col-sm-8">
								<!-- <textarea id="content1" name="content" style="width: 350px; height: 250px;"></textarea> -->
								 <textarea id="addeditor_id" name="contenttt" style="width:100%;height:250px;border: 0 none;visibility:hidden;"></textarea>
            								<textarea rows="" cols="" name="content" id="content1" style="width:350px;height:250px;display:none;"></textarea>
							</div>
						</div>
						

					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
						<button type="button" class="btn btn-primary" onclick="addNews()">
					添加
				</button>
				
				</form>
				
					</div>
				</div>
				
			</div>
			
		</div>
		
		</div>
		
		<!--编辑弹出层-->
		<div class="update_modal">
		
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content" style="background-color:#A6A6A6;">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>

						<h4 class="modal-title" id="myModalLabel">
					编辑
				</h4>
					
					<form class="form-horizontal" role="form" id="neweditform" method="post" enctype="multipart/form-data">
						
						<input type="hidden" id="id" name="id" value=""/>
						
						<div class="form-group">
							<label for="title" class="col-sm-2 control-label">标题</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="title" name="title">
							</div>
						</div>
						
						<div class="form-group">
							<label for="writer" class="col-sm-2 control-label">作者</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="writer" name="writer">
							</div>
						</div>
						
						<div class="form-group">
							<label for="image11" class="col-sm-2 control-label">图片</label>
							<div class="col-sm-4">
								<img id="image11" name="image11" src="${pageContext.request.contextPath }/img/1.png" width="50px" height="50px"/>
    							<input type="hidden" name="image" id="npiccc" value="">
								<input type="file" name="imgsss" id="imgsss" onchange="imgfuunnn()">
							</div>
						</div>
						
						<div class="form-group">
							<label for="desc" class="col-sm-2 control-label">描述</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" id="desc" name="desc">
							</div>
						</div>
						
						<div class="form-group">
							<label for="isshow" class="col-sm-2 control-label">是否发布</label>
							<div class="col-sm-4">
								<select id="isshow" name="isshow">
								<option value="">请选择</option>
								<option value="1">是</option>
								<option value="2">否</option>
								</select>
							</div>
						</div>
						
						<div class="form-group">
							<label for="ishot" class="col-sm-2 control-label">是否热门</label>
							<div class="col-sm-4">
								<select id="ishot" name="ishot">
							    <option value="">请选择</option>
								<option value="1">是</option>
								<option value="2">否</option>
								</select>
							</div>
						</div>
						
						<div class="form-group">
							<label for="content" class="col-sm-2 control-label">内容</label>
							<div class="col-sm-8">
								<!-- <textarea id="content" name="content" style="width: 350px; height: 250px;"></textarea> -->
								<textarea id="edit_news" name="newscontent" style="width:100%;height:250px;border: 0 none;"></textarea>
            								<textarea rows="" cols="" name="content" id="content" style="width:100%;height:250px;display: none"></textarea>
							</div>
						</div>
						
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
						<button type="button" class="btn btn-primary" onclick="updateNews()">
					修改
				</button>
				
				</form>
				
					</div>
				</div>
				
			</div>
			
		</div>
		
		</div>
		
    <!-- /#wrapper -->
<!-- Nav CSS -->
<link href="${pageContext.request.contextPath }/css/custom.css" rel="stylesheet">
<!-- Metis Menu Plugin JavaScript -->
<script src="${pageContext.request.contextPath }/js/metisMenu.min.js"></script>
<script src="${pageContext.request.contextPath }/js/custom.js"></script>
<script type="text/javascript">
/*添加图片上传*/
function imgfun12(){
	
	var obj = {
			url:"<%=basePath%>adminNews/uploadadpic.html",
			dataType:"json",
			type:"post",
			success: function (result) {
				var objs;
				/* if((typeof result == 'object') && result.constructor == Object){
					objs = result;
				}else{
					objs = eval("("+result+")");
				} */
				$("#image1").attr("width","220px");
				$("#image1").attr("height","260px");
				$("#image1").attr("src",result);
				$("#picc").val(result);
				$("#image1").removeClass("hidden");
			}
	};			
	$("#newsaveform").ajaxSubmit(obj);

}
/* 添加 */
function addNews() {
	
        $("#content1").val($("#addeditor_id").val()); //把KindEditor产生的html代码放到schtmlnr里面，用于提交
        $.post(
    			"<%=basePath%>adminNews/addNews.html",
    			$("#newsaveform").serialize(),
    			function (data) {
    				alert("添加成功!");
    				location.href="<%=basePath%>adminNews/Newslist.html";
    			}
    	);
	
	
	
}

<%-- $.post(
		"<%=basePath%>adminNews/addNews.html",
		$("#newsaveform").serialize(),
		function (data) {
			alert("添加成功!");
			location.href="<%=basePath%>adminNews/Newslist.html";
		}
); --%>

/* 编辑页面图片上传 */
function imgfuunnn(){
var obj = {
		url:"<%=basePath%>adminNews/uploadEditpic.html",
		dataType:"json",
		type:"post",
		success: function (result) {
			var objs;
			/* if((typeof result == 'object') && result.constructor == Object){
				objs = result;
			}else{
				objs = eval("("+result+")");
			} */
			$("#image11").attr("width","220px");
			$("#image11").attr("height","260px");
			$("#image11").attr("src",result);
			$("#npiccc").val(result);
			/* $("#pimage1").removeClass("hidden"); */
		}
};
$("#neweditform").ajaxSubmit(obj);
}

/* 编辑页面信息回显 */
function editNews(id) {
	$.post(
			"<%=basePath%>adminNews/editNews.html",
			{"id":id},
			function (data) {
				KindEditor.html('#edit_news',data.content);
				$("#id").val(data.id);
				$("#title").val(data.title);
				$("#writer").val(data.writer);
				$("#image11").attr('src',data.image);
				$("#npiccc").val(data.image);
				$("#desc").val(data.desc);
				$("#isshow").val(data.isshow);
				$("#ishot").val(data.ishot);
			},
			"json"
	);
	
}

/* 修改页面 */
 function updateNews() {
	 $("#content").val($("#edit_news").val()); //把KindEditor产生的html代码放到content里面,用于提交
	$.post(
		"<%=basePath%>adminNews/updateNewss.html",
		$("#neweditform").serialize(),
		function (data) {
			alert("修改成功!");
			location.href="<%=basePath%>adminNews/Newslist.html";
		}
		
	);
}

/* 删除 */
function deleteNews(id) {
	var y = confirm("您确定要删除吗?");
	if(y){
		$.post(
			"<%=basePath%>adminNews/delNews.html",
			{"id":id},
			function (data) {
				alert("删除成功!");
				location.href="<%=basePath%>adminNews/Newslist.html";
			}
		);
	}
}
</script>
</body>
</html>